package com.bwie.system.controller;

import com.bwie.common.domain.*;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.system.FastUtil;
import com.bwie.system.service.ShopService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author：作者姓名
 * @Package：com.bwie.system.controller
 * @Project：_yk
 * @name：ShopController
 * @Date：2024/6/17 10:44
 */
@RestController
@RequestMapping("/Shop")
public class ShopController {

    @Autowired
    private ShopService shopService;

    @Autowired
    private FastUtil fastUtil;



    @PostMapping("/toShop")
    public Result<PageResult<Shop>> ShopAll(@RequestBody Shop shop){
        PageHelper.startPage(shop.getPageNum(),shop.getPageSize());
        List<Shop> shops = shopService.ShopAll(shop);
        PageInfo<Shop> info = new PageInfo<>(shops);
        return PageResult.toResult(info.getTotal(), shops);
    }
    @PostMapping("/toShopping")
    public Result<List<Shopping>> ShopAll(){
        List<Shopping> shops = shopService.ShoppingAll();
        return Result.success(shops);
    }

    @PostMapping("/getOder")
    public Result<List<Oder>> getOder(){
        List<Oder> shops = shopService.getOder();
        return Result.success(shops);
    }




    @PostMapping("/listAll")
    public Result<List<TypeInfoVo>> listAll(){
        List<TypeInfoVo> typeInfos = shopService.listAll();
        return Result.success(typeInfos);
    }

    @PostMapping("/getType")
    public Result<List<Type>> getType(){
        List<Type> typeInfos = shopService.getType();
        return Result.success(typeInfos);
    }

    @PostMapping("/upload")
    public Result upload(MultipartFile file){
        String upload="";
        try {
            upload = fastUtil.upload(file);
            if(upload.length()<=0){
                return Result.error("上传失败！");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return Result.success("http://122.51.211.93:8888/"+upload,"上传成功！");
    }

    @PostMapping("/getAdd")
    public Result Add(@RequestBody Shop shop){
        Integer add = shopService.getAdd(shop);
        return Result.success(add,"添加成功");
    }


    @PostMapping("/getAdds")
    public Result getAdds(@RequestBody Shop shop){
        Integer add = shopService.getAdds(shop);
        return Result.success(add,"添加成功");
    }

    @PostMapping("/updStats")
    public Result updStats (@RequestParam String stats,String id){
        Integer add = shopService.updStats(stats,id);
        return Result.success(add,"修改成功");
    }

    @PostMapping("/Del")
    public Result Del (@RequestParam String id){
        Integer add = shopService.Del(id);
        return Result.success(add,"删除成功");
    }

    @PostMapping("/handleDel")
    public Result handleDel (){
        Integer add = shopService.handleDel();
        return Result.success(add,"申请成功");
    }

    @PostMapping("/handleDelete")
    public Result Delss (@RequestParam String price, String userName){
        Integer add = shopService.handleDelete(price,userName);
        return Result.success(add,"结算成功");
    }
    @PostMapping("/handleDeletes")
    public Result Dels (@RequestBody String ids []){
        Integer add = shopService.handleDeletes(ids);
        return Result.success(add,"结算成功");
    }















}
